package org.karelun.rabbit.bridge.ui.action;

import java.util.Collection;

import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.UnexecutableCommand;
import org.eclipse.emf.edit.command.PasteFromClipboardCommand;
import org.eclipse.ui.IWorkbenchPart;
import org.karelun.rabbit.bridge.ITransactionEditingDomain;
import org.karelun.rabbit.bridge.ITransactionEditingDomainProvider;

public class RabbitPasteAction extends RabbitCommandActionHandler{

	public RabbitPasteAction(ITransactionEditingDomain domain) {
		super(domain,"Paste");
	}
	
	public RabbitPasteAction(){
		super(null,"Paste");
	}
	
	@Override
	protected Command createCommand(Collection<Object> selection) {
		if(selection.size()==1){
			return PasteFromClipboardCommand.create(editingDomain, selection.iterator().next(), null);
		}
		return UnexecutableCommand.INSTANCE;
	}
	
	public void setActiveWorkbenchPart(IWorkbenchPart workbenchPart){
		if(workbenchPart instanceof ITransactionEditingDomainProvider){
			editingDomain=((ITransactionEditingDomainProvider)workbenchPart).getTransactionEditingDomain();
		}
	}

}
